import {
    createRouter,
    createWebHashHistory,
    createWebHistory,
} from "vue-router";
const asdhj = 0
const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/",
            name: "/",
            redirect: "/login",
        },
        {
            path: "/login",
            name: "login",
            component: () => import("../view/login.vue"),
        },
        {
            path: "/index",
            name: "index",
            component: () => import("../view/index.vue"),
            redirect: "/index/main",
            meta: {
                title: "首页",
            },
            children: [
                {
                    path: "/index/main",
                    name: "test",
                    component: () => import("../view/3dgis/test.vue"),
                },
            ],
        },
        {
            path: "/editor",
            name: "editor",
            component: () => import("../view/other/editor.vue"),
        },
        {
            path: "/dataManagement",
            name: "dataManagement",
            redirect: "/dataManagement/mark",
            component: () => import("../view/dataManagement/index.vue"),
            children: [
                {
                    path: "/dataManagement/mark",
                    name: "mark",
                    meta: {
                        title: "地图标记",
                        show: true,
                    },
                    component: () => import("../view/dataManagement/mark.vue"),
                },
                {
                    path: "/dataManagement/uav",
                    name: "uav",
                    meta: {
                        title: "无人机地图",
                        show: true,
                    },
                    component: () => import("../view/dataManagement/uavList.vue"),
                },
                {
                    path: "/dataManagement/user",
                    name: "user",
                    meta: {
                        title: "用户管理",
                        show: asdhj?true:false,
                    },
                    component: () => import("../view/dataManagement/user/index.vue"),
                },
                {
                    path: "/dataManagement/changePassword",
                    name: "changePassword",
                    meta: {
                        title: "修改密码",
                        show: true,
                    },
                    component: () => import("../view/dataManagement/user/changePassword.vue"),
                },
            ],
        },
    ],
});
router.beforeEach((to, from, next) => {
	// 判断有没有登录
    const user = localStorage.getItem("token");
    if (!user && to.path !== '/login') {
            next('/login');
    } else {
		next();
	}
});
export default router;
